/*
 * Copyright (C) 2017 yixun All Rights Reserved.
 * 
 * OperationLogDto.java
 */
package com.yixun.qfbao.model.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.yixun.qfbao.model.OperationLog;
import lombok.Data;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * [文件名称]<br>
 * OperationLogDto.java<br>
 * <br>
 * [文件描述]<br>
 * 用户操作日志表 数据辅助类<br>
 * <br>
 * [修改记录]<br>
 * 2017-08-07 16:20:41 创建 陶俊代码生成器<br>
 * 
 * @author 陶俊代码生成器
 * @version 1.00
 */
@Data
public class OperationLogDto extends OperationLog {
	private static final long serialVersionUID = 1L;
	/**
	 *需要正序字段名
	 */
	private List<String> asc;
	/**
	 *需要逆序字段名
	 */
	private List<String> desc;
	/**
	 *排序SQL
	 */
	private String orders;
    
    /**
	 *  添加需要正序字段名
	 */
	public void addAsc(String col){
		if(asc==null){
			asc = new LinkedList<String>();
		}
		asc.add(col);
	}
	
	/**
	 *  清空需要正序字段名
	 */
	public void cleanAsc(){
		asc = null;
	}
	
	/**
	 *  添加需要逆序字段名
	 */
	public void addDesc(String col){
		if(desc==null){
			desc = new LinkedList<String>();
		}
		desc.add(col);
	}

	/**
	 * 公司名稱
	 */
	private String companyName;
	 /**
	 * 操作人姓名
	 */
	private String accountName;

	/**
	 *  清空需要逆序字段名
	 */
	public void cleanDesc(){
		desc = null;
	}
	
	/**
	 *  如果排序SQL为空根据需要正逆序的字段名拼接排序SQL
	 */
	public String  getOrders() {
		StringBuilder orderStr = null;
		StringBuilder ascStr;
		StringBuilder descStr;
		if(orders==null){
			if(asc!=null){
				ascStr = new StringBuilder();
				orderStr = new StringBuilder();
				String pex = "";
				for(String a : asc){
					ascStr.append(pex+a);
					pex = ",";
				}
				orderStr.append(ascStr.toString()+" ASC");
			}
			if(desc!=null){
				descStr = new StringBuilder();
				String pex = "";
				for(String d : desc){
					descStr.append(pex+d);
					pex = ",";
				}
				if(orderStr==null){
					orderStr = new StringBuilder();
					orderStr.append(descStr.toString()+" DESC");
				}else{
					orderStr.append(","+descStr.toString()+" DESC");
				}
			}
			orders = orderStr!=null?orderStr.toString():null;
		}
		
		return orders;
	}

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date optTimeBefore;
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date optTimeAfter;

}
